package cn.chinasyq.photoquan.user.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.TextView;

import cn.chinasyq.photoquan.R;
import cn.chinasyq.photoquan.user.bean.VipInfo;
import cn.chinasyq.photoquan.view.LoadView;
import cn.master.util.utils.ToastUtil;
import cn.master.volley.models.response.handler.ResponseHandler;

/**
 * Created by 一搏 on 2015/11/27.
 */
public class VipInfoActivity extends Activity implements ResponseHandler.OnSucceedListener, ResponseHandler.OnFailedListener, View.OnClickListener {
    private static final String TAG_REFRESH = "refresh";
    TextView textView;
    private LoadView loadView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vip_info);
        loadView = (LoadView) findViewById(R.id.loadview);
        loadView.setOnReLoadClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                refreshDate();
            }
        });
        textView = (TextView) findViewById(R.id.tv_content);
        textView.setMovementMethod(new ScrollingMovementMethod());
        refreshDate();
    }

    protected void refreshDate() {
        loadView.setStatus(LoadView.Status.loading);
        ResponseHandler handler = new ResponseHandler(TAG_REFRESH);
        handler.setOnSucceedListener(this);
        handler.setOnFailedListener(this);
    }

    @Override
    public void onSucceed(String tag, boolean isCache, Object data) {
        if (data instanceof VipInfo) {
            textView.setText(((VipInfo) data).getContent());
            loadView.setStatus(LoadView.Status.successed);
        } else {
            loadView.setStatus(LoadView.Status.data_error);
        }
    }

    @Override
    public void onFailed(String tag, ResponseHandler.FailedStatus status, int resultCode, String msg) {
        if (msg == null) {
            switch (status) {
                case DATA_ERROR:
                    ToastUtil.show(getApplicationContext(), R.string.tip_data_error);
                    break;
                case NETWORK_ERROR:
                    ToastUtil.show(getApplicationContext(), R.string.servererrortips);
                    break;
            }
        } else {
            ToastUtil.show(getApplicationContext(), msg);
        }
        loadView.setStatus(LoadView.Status.network_error);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ibtn_back:
                onBackPressed();
                break;
            case R.id.btn_pay:
                callpay();
                break;
        }
    }

    public void callpay() {
startActivity(new Intent(this,PaymentGameActivity.class));
    }
}
